package com.gui;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.JLabel;
import javax.swing.JButton;

import com.client.ConsumerNotow;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JScrollPane;
import java.awt.Font;
import java.awt.Color;
import java.awt.SystemColor;
import javax.swing.UIManager;
import javax.swing.border.EtchedBorder;
import javax.swing.border.LineBorder;
import javax.swing.border.MatteBorder;
import javax.swing.JTextPane;
import javax.swing.JScrollBar;
import javax.swing.border.TitledBorder;
import javax.swing.JList;

public class mainFrame extends JFrame {

	private JPanel contentPane;
	private JTable jTable1;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					mainFrame frame = new mainFrame();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	@SuppressWarnings("serial")
	public mainFrame() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 673, 543);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		/*btn Refresh*/
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(10, 69, 637, 160);
		contentPane.add(scrollPane);
		
		jTable1 = new JTable();
		scrollPane.setViewportView(jTable1);
		

		jTable1.setModel(new DefaultTableModel(
			new Object[][] {
			},
			new String[] {
				"ID", "Data", "Nazwa", "Bie\u017C\u0105cy", "Odniesienie", "Zmiana", "Otwarcie", "Min", "Max", "Wolumen", "Warto\u015B\u0107"
			}
		) {
			boolean[] columnEditables = new boolean[] {
				false, false, false, false, false, false, true, false, false, false, false
			};
			public boolean isCellEditable(int row, int column) {
				return columnEditables[column];
			}
		});
		
		JLabel lblNewLabel = new JLabel("Notowania");
		lblNewLabel.setForeground(SystemColor.textHighlight);
		lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 15));
		lblNewLabel.setBounds(10, 25, 147, 19);
		contentPane.add(lblNewLabel);
		
		JLabel lblNewLabel_1 = new JLabel("<userName>");
		lblNewLabel_1.setBounds(583, 11, 64, 14);
		contentPane.add(lblNewLabel_1);
		
		JLabel lblNewLabel_2 = new JLabel("mClient");
		lblNewLabel_2.setFont(new Font("Tahoma", Font.BOLD, 26));
		lblNewLabel_2.setForeground(new Color(0, 128, 128));
		lblNewLabel_2.setBounds(264, 1, 110, 23);
		contentPane.add(lblNewLabel_2);
		
		JPanel panel = new JPanel();
		panel.setToolTipText("");
		panel.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Ustawienia", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panel.setBounds(20, 240, 230, 201);
		contentPane.add(panel);
		panel.setLayout(null);
		
		JList jList1 = new JList();
		jList1.setBounds(10, 59, 89, 132);
		panel.add(jList1);
		
		JList jList2 = new JList();
		jList2.setBounds(119, 59, 89, 132);
		panel.add(jList2);
		
		JButton btnNewButton_1 = new JButton("Poka\u017C sp\u00F3ki");
		btnNewButton_1.setBounds(10, 21, 87, 23);
		panel.add(btnNewButton_1);
		
		JLabel lblNewLabel_3 = new JLabel("ilosc rekord\u00F3w");
		lblNewLabel_3.setBounds(125, 25, 83, 14);
		panel.add(lblNewLabel_3);
		
		JPanel panel_1 = new JPanel();
		panel_1.setBorder(new TitledBorder(null, "Wy\u015Bwietlanie", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panel_1.setBounds(264, 240, 171, 104);
		contentPane.add(panel_1);
		panel_1.setLayout(null);
		JButton btnNewButton = new JButton("Wszystkie");
		btnNewButton.setBounds(37, 27, 89, 23);
		panel_1.add(btnNewButton);
		
		JButton btnNewButton_2 = new JButton("Wybrane");
		btnNewButton_2.setBounds(37, 71, 89, 23);
		panel_1.add(btnNewButton_2);
		
		JPanel panel_2 = new JPanel();
		panel_2.setBorder(new TitledBorder(null, "Wykresy", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panel_2.setBounds(445, 240, 154, 104);
		contentPane.add(panel_2);
		panel_2.setLayout(null);
		
		JButton btnNewButton_3 = new JButton("Liniowy");
		btnNewButton_3.setBounds(37, 23, 89, 23);
		panel_2.add(btnNewButton_3);
		
		JPanel panel_3 = new JPanel();
		panel_3.setBorder(new TitledBorder(null, "Wyj\u015Bcie", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panel_3.setBounds(445, 359, 154, 82);
		contentPane.add(panel_3);
		panel_3.setLayout(null);
		
		JButton btnNewButton_4 = new JButton("Zamknij");
		btnNewButton_4.setBounds(55, 48, 89, 23);
		panel_3.add(btnNewButton_4);
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				DefaultTableModel model=(DefaultTableModel) jTable1.getModel();
				 model.setRowCount(0);
				
				String queueName = "notowania.queue";  
				ConsumerNotow consumer = new ConsumerNotow();
	            consumer.consumeMessage(queueName);
	            String[] tokenId = consumer.getId().split(";");
	            String[] tokenData = consumer.getData().split(";");
	            String[] tokenNazwa = consumer.getNazwa().split(";");
	            String[] tokenKursB = consumer.getKursB().split(";");
	            String[] tokenKursOdniesienia = consumer.getKursOdniesienia().split(";");
	            String[] tokenZmiana = consumer.getZmiana().split(";");
	            String[] tokenKursOtwarcia = consumer.getKursOtwarcia().split(";");
	            String[] tokenKursMin = consumer.getKursMin().split(";");
	            String[] tokenKursMax = consumer.getKursMax().split(";");
	            String[] tokenWolumen = consumer.getWolumen().split(";");
	            String[] tokenWartosc = consumer.getWartosc().split(";");
				
				//for (String t : tokenKursB)
	           
	            for(int i=0;i<tokenKursB.length;i++)					
				{
	            	
	            	String pom1 = tokenId[i];
	            	String pom2 = tokenData[i];
	            	String pom3 = tokenNazwa[i];
	            	String pom4 = tokenKursB[i];
	            	String pom5 = tokenKursOdniesienia[i];
	            	String pom6 = tokenZmiana[i];
	            	String pom7 = tokenKursOtwarcia[i];
	            	String pom8 = tokenKursMin[i];
	            	String pom9 = tokenKursMax[i];
	            	String pom10 = tokenWolumen[i];
	            	String pom11 = tokenWartosc[i];
	            	
				System.out.println(pom1);
				System.out.println(pom2);
		 model.addRow(new Object []{				
					pom1,pom2,pom3,pom4,pom5,pom6,pom7,pom8,pom9,pom10,pom11 
	         });
				
			}
								}
		});
		jTable1.getColumnModel().getColumn(0).setPreferredWidth(40);
		jTable1.getColumnModel().getColumn(0).setMinWidth(40);
		jTable1.getColumnModel().getColumn(1).setPreferredWidth(70);
		jTable1.getColumnModel().getColumn(1).setMinWidth(70);
		jTable1.getColumnModel().getColumn(2).setPreferredWidth(100);
		jTable1.getColumnModel().getColumn(2).setMinWidth(100);
		jTable1.getColumnModel().getColumn(3).setPreferredWidth(65);
		jTable1.getColumnModel().getColumn(3).setMinWidth(65);
		jTable1.getColumnModel().getColumn(4).setPreferredWidth(65);
		jTable1.getColumnModel().getColumn(4).setMinWidth(65);
		jTable1.getColumnModel().getColumn(5).setPreferredWidth(45);
		jTable1.getColumnModel().getColumn(5).setMinWidth(45);
		jTable1.getColumnModel().getColumn(6).setPreferredWidth(65);
		jTable1.getColumnModel().getColumn(7).setPreferredWidth(65);
		jTable1.getColumnModel().getColumn(8).setPreferredWidth(65);
	}
}
